package com.zjdiepu.www.rest.api.zx;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zjdiepu.www.base.annotation.Add;
import com.zjdiepu.www.base.core.ApiResponse;
import com.zjdiepu.www.common.consts.SystemConsts;
import com.zjdiepu.www.commpent.handler.TokenUserHelper;
import com.zjdiepu.www.commpent.mapper.zx.ZxCreditQueryVoMapper;
import com.zjdiepu.www.ibiz.zx.IZxCreditQueryService;
import com.zjdiepu.www.ibiz.zx.IZxQueryCreditApplySubService;
import com.zjdiepu.www.model.zx.dto.ZxCreditQuery;
import com.zjdiepu.www.model.zx.dto.ZxQueryCreditApplySub;
import com.zjdiepu.www.model.zx.request.ZxQueryRestRequest;

@RestController
@RequestMapping(value= "ZxQueryCreditController", produces="application/json;charset=UTF-8")
@Api(tags = {"征信结果接口"}, produces="application/json;charset=UTF-8")
public class ZxQueryCreditController {

	@Resource
	private IZxCreditQueryService zxCreditQueryService;
	@Resource
	private IZxQueryCreditApplySubService zxQueryCreditApplySubService;
	@Resource
	private ZxCreditQueryVoMapper zxCreditQueryVoMapper;
	@Resource
    private TokenUserHelper tokenUserHelper;
	
	@ApiOperation(value = "征信内容",response = ZxCreditQuery.class, httpMethod="POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "请求机器标识", required = true, paramType = "header", dataType = "String"),
    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="Ajesget8XF7zNMpt+MM8cr0wI8S+IO6a9giEKNouXWvOO3wWWyaKjSDTqRUtHlcNbjCg1JaPdjRX6dX/O1oGLgE=", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "zxQueryCredit", method = RequestMethod.POST)
	public ApiResponse zxQueryCredit(@Validated(Add.class) @RequestBody ZxQueryRestRequest zxQueryRestRequest){
		tokenUserHelper.getUser();
		String creditQueryId = zxQueryRestRequest.getCreditQueryId();
		ZxCreditQuery zxCreditQuery = zxCreditQueryService.selectById(creditQueryId);
		if(null != zxCreditQuery) {
			String queryCreditApplySubId = zxCreditQuery.getQueryCreditApplySubId();
			if(StringUtils.isNotBlank(queryCreditApplySubId)) {
				ZxQueryCreditApplySub zxQueryCreditApplySub = zxQueryCreditApplySubService.selectById(queryCreditApplySubId);
				if(null != zxQueryCreditApplySub) {
					zxCreditQuery.setCusName(zxQueryCreditApplySub.getCusName());
					zxCreditQuery.setCusNo(zxQueryCreditApplySub.getCusNo());
				}
			}
		}
		zxCreditQueryVoMapper.mapper(zxCreditQuery);
		return ApiResponse.success(zxCreditQuery);
	}
	
}
